import { defineStore } from "pinia";
import { store } from "@/store";
import { useStorage } from "@vueuse/core";
import {getDepartmentOptions} from "@/api/engine";
import {getExCompanyOptions,getExDepartmentOptions} from "@/api/publicApi";


import _ from 'lodash-es'

export const useBaseConfigStore = defineStore("baseConfig", () => {
	
	//所属公司
	const newExCompanyList = ref<any>();
	//所属部门
	const newExDepartmentList = ref<any>();
	
	function initBaseConfig(){
		
		getNewExCompanyList();//获取所属公司
		getNewExDepartmentList();//获取所属部门
	}
	function getNewExCompanyList(){
		getExCompanyOptions({}).then((res) => {
			 console.log('第一次加载配置项->：获取所属公司列表')
			 newExCompanyList.value = res.data;
		}).finally(() => { }) 
	} 
	function getNewExDepartmentList(){
		getExDepartmentOptions({}).then((res) => {
			 console.log('第一次加载配置项->：获取所属部门')
			 newExDepartmentList.value = res.data;
		}).finally(() => { }) 
	} 
	
	

	return {
		initBaseConfig,
		newExCompanyList,//获取专属公司列表
		newExDepartmentList//获取专属部门
		
	};
},{
	persist: {
		key: 'baseConfig', 
		storage: localStorage, 
		paths: ['deparCompanyList'],
	},
});